from flask import Flask
from jwt import ExpiredSignatureError, InvalidTokenError
from werkzeug.exceptions import BadRequest

app = Flask(__name__)


@app.errorhandler(BadRequest)
def handleBadRequest():
    from CommonResponse import CommonResponse
    return CommonResponse.requestFailureStatusAndMessage(2, "参数不合法")


# 可继续补充异常处理，自定义异常，然后抛出，进行处理
@app.errorhandler(ExpiredSignatureError)
def handle_expired_signature_error(e):
    from myapp.utils.CommonResponse import CommonResponse
    return CommonResponse.requestFailureStatusAndMessage(10, "需要登录")


@app.errorhandler(InvalidTokenError)
def handle_invalid_token_error(e):
    from myapp.utils.CommonResponse import CommonResponse
    return CommonResponse.requestFailureStatusAndMessage(10, "需要登录")
